home *** CD-ROM | disk | FTP | other *** search
- /*
- SetSpeakerVol XCMD v1.1
-
- ©1991 Apple Computer, Inc.; by Mike Byrne
-
- This XCMD may be used to set the speaker volume, just as if in the Control Panel. It is easy to change
- the volume with a simple toolbox call, but changing the parameter RAM so that the Control Panel knows
- about it is a little trickier. Watch carefully...
-
- Form:
- SetSpeakerVol <volume>
-
- # the MPW 3.2 build commands:
- C -b SetSpeakerVol.c
- Link -w -t STAK -c WILD -rt XCMD=611 ∂
- -m ENTRYPOINT ∂
- -sg SetSpeakerVol ∂
- SetSpeakerVol.c.o ∂
- "{Libraries}HyperXLib.o" ∂
- "{Libraries}Runtime.o" ∂
- "{Libraries}Interface.o" ∂
- "{CLibraries}StdCLib.o" ∂
- -o "teststack"
- */
-
- #include <Types.h>
- #include <Sound.h>
- #include <string.h>
- #include <Memory.h>
- #include <SysEqu.h>
- #include "HyperXCmd.h"
-
- #define NULL (long) 0
- #define NIL (long) 0
-
- #define kNumParams 1
-
-
- /* prototypes */
- void ErrorBack(XCmdPtr paramPtr, char *message);
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount );
- void UnlockParams ( XCmdPtr paramPtr, short paramCount );
-
-
- pascal void EntryPoint(XCmdPtr paramPtr)
- {
- /* variable declarations */
- long volNum;
- Byte* pRam;
- char volString[10];
-
-
- /* move high and lock the parameters. */
- MoveLockParams(paramPtr, paramPtr->paramCount);
-
- /* check for copyright or syntax help request */
- if (!strcmp( (char*)*paramPtr->params[0], "!") ) {
- ErrorBack(paramPtr, "v1.1, ©1991 Apple Computer, Inc.; by Mike Byrne");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- } else if (!strcmp ( (char*)*paramPtr->params[0], "?") ) {
- ErrorBack(paramPtr, "SetSpeakerVol syntax is 'SetSpeakerVol <volume>'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
- /* not a copyright or help request. */
- /* check for correct number of parameters */
- if (paramPtr->paramCount != kNumParams) {
- ErrorBack(paramPtr, "Error: SetSpeakerVol syntax is 'SetSpeakerVol <volume>'");
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
- }
-
- /* this is the real thing. Convert the parameter to a pascal string, then that to a number. */
- strcpy(volString, (char*) *paramPtr->params[0]);
- c2pstr(volString);
- StringToNum(volString, &volNum);
- if (volNum < 0 ) { volNum = 0; }
- if (volNum > 7 ) { volNum = 7; }
-
- /* Now, set the volume from the toolbox, set the address of the byte, and set the byte of pRAM. */
- SetSoundVol( (short) volNum);
- (long) pRam = SPVolCtl;
- *pRam = (Byte) volNum;
-
- /* we're done. */
- UnlockParams(paramPtr, paramPtr->paramCount);
- return;
-
- }
-
-
-
-
-
-
- /* allocate and load up paramPtr->returnValue with a string
- -------------------------------------------------------- */
- void ErrorBack(XCmdPtr paramPtr, char *message)
- {
- Handle mesHnd;
-
- /*
- Allocate space for an error message.
- Copy the string into it.
- Return the handle to HyperCard.
- */
- mesHnd = NewHandle((long)(strlen(message)+1));
- if (mesHnd == nil) return;
- strcpy((char *)*mesHnd,message);
- paramPtr->returnValue = mesHnd;
- }
-
-
-
- /* move high and lock down all parameters
- ----------------------------------------------------------------------- */
- void MoveLockParams ( XCmdPtr paramPtr, short paramCount )
- {
- short i;
-
- for(i=0; i <= paramCount-1; i++)
- {
- MoveHHi(paramPtr->params[i]);
- HLock(paramPtr->params[i]);
- }
- }
-
-
-
-
- /* unlock all parameter handles in the XCmdBlock
- --------------------------------------------- */
- void UnlockParams ( XCmdPtr paramPtr, short paramCount )
- { short i;
-
- for(i=0; i <= paramCount-1; i++)
- { HUnlock(paramPtr->params[i]);}
- }
-